<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: wsh
 * @Date: 2023-06-20 18:06:09
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2024-07-25 15:19:24
-->
<!-- 机构员工管理 -->
<template>
	<BaseContainer>
		<aplid-base-crud ref="crud" class="w-100" v-bind="baseConfig" :operateFormate="onOperateFormate" :paramsObj="{ creditCode }">
			<template #menuLeftAppend>
				<el-button style="margin-left: 10px" type="primary" @click="handleOperate('handleEntry', {}, '办理入职')">办理入职</el-button>
			</template>
			<template #menuColumn="{ row }">
				<el-button v-if="row.status == 0" text type="primary" @click="handleOperate('level', row, '办理请假-添加')">办理请假</el-button>
				<el-button v-if="row.status == 0" text type="primary" @click="handleOperate('dimission', row, '办理离职-添加')">办理离职</el-button>
			</template>
			<template #levelDialog="{ row }">
				<AddLevel :newData="row" @refresh="handleRefreshPage" @back="handleRefreshPage"></AddLevel>
			</template>
			<template #dimissionDialog="{ row }">
				<AddDimission :newData="row" @refresh="handleRefreshPage" @back="handleRefreshPage"></AddDimission>
			</template>
			<template #handleEntryDialog="{ row }">
				<HandleEntry :newData="row" @refresh="handleRefreshPage" @back="handleRefreshPage"></HandleEntry>
			</template>
			<template #editDialog="{ row }">
				<EditPart :newData="row" @refresh="handleRefreshPage" @back="handleRefreshPage"></EditPart>
			</template>
		</aplid-base-crud>
		<AplidDialog v-model="visible" width="75%" :rowData="organizationInfo">
			<DetailPage v-if="visible" :nowRowData="rowData" @refresh="handleRefreshPage" @back="handleRefreshPage"></DetailPage>
		</AplidDialog>
	</BaseContainer>
</template>

<script setup lang="ts">
import { baseConfig } from './config'
import AddLevel from './components/addLevel.vue'
import EditPart from './components/eidtPage.vue'
import AddDimission from './components/addDimission.vue'
import HandleEntry from './components/handleEntry.vue'
import DetailPage from './DetailPage/index.vue'
import AplidDialog from '@/views/elderlyInstitute/components/AplidDialog/index.vue'
import { getStore } from '@/utils/store'
import apiMod from '@/apiMod/index'

let organizationInfo = ref({})
const userInfo =  getStore('userInfo') ||{}
let creditCode = userInfo.organizationId
creditCode = creditCode == 1 ? undefined : creditCode

let visible = ref(false)
let rowData: any = ref({})
let operateType = ref('detail')
let crud = ref()
const handleOperate = (type, row, title) => {
	nextTick(() => {
		crud.value.handleOperate(type, row, title)
	})
}
const handleRefreshPage = () => {
	nextTick(() => {
		crud.value.refreshChange({}, false)
	})
}
const onOperateFormate = (data, type) => {
	return new Promise((resolve, reject) => {
		if (type == 'detail') {
			rowData.value = data
			apiMod
				.view_dpServiceOrgBase_creditCode(data.creditCode)
				.then((res) => {
					organizationInfo.value = res.data || {}
					visible.value = true
				})
				.catch(() => {
					visible.value = true
				})
		} else {
			resolve(data)
		}
	})
}
</script>

<style scoped></style>
